import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { tourRouteList } from '@apps/ant-bus/src/views/business/tourManage/tourRoute/data/api';
import { tourTimeList } from '@apps/ant-bus/src/views/business/tourManage/tourTime/data/api';
import { RenderType } from '@pkg/setting';
import { employeeList } from '@apps/ant-bus/src/views/business/employeeManage/employee/data/api';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';

export const columns: BasicColumn[] = [
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 150,
  },
  {
    title: '旅游路线',
    dataIndex: 'tourRouteName',
    width: 220,
  },
  {
    title: '出行时间段',
    dataIndex: 'tourTime',
    width: 175,
  },
  {
    title: '联系人姓名',
    dataIndex: 'userName',
    width: 150,
  },
  {
    title: '联系人电话',
    dataIndex: 'userPhone',
    width: 110,
  },
  {
    title: '出行人数',
    dataIndex: 'tourPeopleNum',
    width: 90,
  },
  {
    title: '会员卡号',
    dataIndex: 'vipCardNo',
    width: 160,
  },
  {
    title: '开卡地',
    dataIndex: 'airportName',
    width: 160,
  },
  {
    title: '销售',
    dataIndex: 'employeeName',
    width: 100,
  },
  {
    title: '会员卡类型',
    dataIndex: 'vipCardType',
    width: 90,
    dictData: [
      { label: '电子卡', value: 1 },
      { label: '实体卡', value: 2 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '旅游价格',
    dataIndex: 'tourPrice',
    width: 100,
  },
  {
    title: '出发地',
    dataIndex: 'tourStartPlace',
    width: 150,
  },
  {
    title: '返回地',
    dataIndex: 'tourEndPlace',
    width: 150,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'tourRouteId',
    label: '旅游线路',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: ({ formActionType, formModel }) => {
      return {
        api: tourRouteList,
        labelField: 'tourRouteName',
        valueField: 'tourRouteId',
        immediate: true,
        showSearch: true,
        onChange: tourRouteId => {
          formModel.tourTimeId = null;
        },
      };
    },
  },
  {
    field: 'tourTimeId',
    label: '时间段',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: ({ formModel }) => {
      let tourRouteId = formModel.tourRouteId;
      if (tourRouteId) {
        return {
          api: tourTimeList,
          params: { tourRouteId: tourRouteId },
          labelField: 'tourTimeStr',
          valueField: 'tourTimeId',
          immediate: true,
          showSearch: true,
        };
      } else {
        return [];
      }
    },
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'userName',
    label: '联系人姓名',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'userPhone',
    label: '联系人电话',
    component: 'Input',
    colProps: { span: 5 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '旅游记录Id',
    field: 'tourRecordId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '电子会员卡Id',
    field: 'userGoodsId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '旅游线路',
    field: 'tourRouteId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formActionType, formModel }) => {
      return {
        api: tourRouteList,
        labelField: 'tourRouteName',
        valueField: 'tourRouteId',
        immediate: true,
        showSearch: true,
        onChange: tourRouteId => {
          formModel.tourTimeId = null;
        },
      };
    },
  },
  {
    label: '时间段',
    field: 'tourTimeId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      let tourRouteId = formModel.tourRouteId;
      if (tourRouteId) {
        return {
          api: tourTimeList,
          params: { tourRouteId: tourRouteId },
          labelField: 'tourTimeStr',
          valueField: 'tourTimeId',
          immediate: true,
          showSearch: true,
        };
      } else {
        return [];
      }
    },
  },
  {
    field: 'employeeId',
    label: '所属销售',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: employeeList,
      params: { handlerName: 'busEmployeeListHandler' },
      labelField: 'employeeAccountName',
      valueField: 'employeeId',
      immediate: true,
      showSearch: true,
    },
    dynamicDisabled: ({ values }) => {
      if (values.userGoodsId) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    field: 'airportId',
    label: '开卡机场',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: airportList,
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
    },
    dynamicDisabled: ({ values }) => {
      if (values.userGoodsId) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '联系人姓名',
    field: 'userName',
    component: 'Input',
    required: false,
  },
  {
    label: '联系人电话',
    field: 'userPhone',
    component: 'Input',
    required: false,
  },
  {
    label: '会员卡号',
    field: 'vipCardNo',
    component: 'Input',
    required: true,
    dynamicDisabled: ({ values }) => {
      if (values.userGoodsId) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '会员卡类型',
    field: 'vipCardType',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '电子卡', value: 1 },
        { label: '实体卡', value: 2 },
      ],
    },
    dynamicDisabled: ({ values }) => {
      if (values.userGoodsId) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '旅游价格',
    field: 'tourPrice',
    component: 'InputNumber',
    defaultValue: 0,
    required: true,
  },
  {
    label: '旅游时间',
    field: 'tourStartTime',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '出发地',
    field: 'tourStartPlace',
    component: 'Input',
    required: true,
  },
  {
    label: '返回地',
    field: 'tourEndPlace',
    component: 'Input',
    required: false,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
];
